<?php

class AjaxController extends Controller
{
	
	public function actionSaveItemDependency()
	{
		print_r($_POST);
	}
	
	public function actionAddComponent()
	{
		
		$bom = new BillOfMaterials;
		
		$bom->attributes=$_POST['Component'];
		
		$bom->reference_id = "{$bom->item_id}-{$bom->component_id}-". microtime();
		
		// validation set to false for the time being
		$bom->save(false);
		
		$component = $bom->component;
		
		$output_params = array(
			'id' => $component->id,
			'code' => $component->code,
			'name' => $component->short_description,
			'category' => $component->itemCategory->category,
			'type' => $component->itemType->type,
			'quantity' => $bom->quantity,
			'cost' => $component->getCost(),
			'total' => ($bom->quantity * $component->getCost())
		);
		
		echo json_encode($output_params);

	}
	
}